var mydialog;

$(function(){
	$("#box-tabs").tabs();
	$("#cjzl").css("color","black");
	$("#cjzl").click(function(){
		showdiv1();
	});
	
	$("#xgyj").click(function(){
		showdiv2();
	});
	
	$("#other").click(function(){
		showdiv6();
	});
	
	var option={
			 dateFormat:"yy-mm-dd",
			 showOn: "button",
			 buttonImage: "../../../Public/images/date_16x16.gif",
			 buttonImageOnly: true,
			 changeMonth:true,
			 changeYear:true
	};
	 $( "#qyrq" ).datepicker(option);
	 $( "#zyqsr" ).datepicker(option);
	 $( "#zydqr" ).datepicker(option);

});

function checkform(){;
		$(".tips").html("<span style='font-size:30px;color:green;'>√</span>");
		var error=0;
		var check=$(".check").get();
		$.each(check,function(key,value){
			$(this).attr("style","");
			if(value["value"]==''){
				$(this).attr("style","border:1px solid red");
				error++;
			}
		});
		
		if(error!=0){
			$("#cjzl").css("color","black");
			$("#xgyj").css("color","#3F90E8");
			$("#cjkh").css("color","#3F90E8");
			$("#skmx").css("color","#3F90E8");
			$("#dszy").css("color","#3F90E8");
			$("#other").css("color","#3F90E8");
			$("#selltable1").css("display","block");
			$("#selltable2").css("display","none");
			$("#selltable3").css("display","none");
			$("#selltable4").css("display","none");
			$("#selltable5").css("display","none");
			$("#selltable6").css("display","none");
			$(".tips").html("<span style='font-size:30px;color:red;'>注：紅色邊框的輸入框為必填項</span>");
			return ;
		}
		
		var wtybh=$("#wtybh").val();
		var czfys1=$("#czfys1").val();//出租方
		var yj=$("#yj").val();
		var cjbh=$("#cjbh").val();
		var czfss1=$("#czfss1").val();//出租方
		var dj=$("#dj").val();
		var casename=$("#casename").val();
		var czfys=$("#czfys").val();
		var zq=$("#zq").val();
		var qyrq=$("#qyrq").val();
		var czfss=$("#czfss").val();
		var status_code=$("#status_code").val();
		var cje=$("#cje").val();
		var cysm=$("#cysm").val();
		var total_yj=$("#total_yj").val();
		var remark=$("#remark").val();
		var zyqsr=$("#zyqsr").val();
		var zydqr=$("#zydqr").val();
		var jyaqzl=$("#jyaqzl").val();
		var jyaq_code=$("#jyaq_code").val();
		
		mydialog=art.dialog({title:'請稍候...',lock:true});
		
		$.ajax({
			type:'post',
			url:'turnover_data_save',
			dataType:'json',
			data:{hybh:wtybh,turnover_code:cjbh,casename:casename,turnover_m:cje,total_perf:total_yj,trans_sec:jyaqzl,trans_sec_code:jyaq_code,deposit:yj,earnest:dj,lease:zq,status_code:status_code,qy_date:qyrq,rent_start:zyqsr,rent_end:zydqr,cysm:cysm,remark:remark,buyer_ys:czfys,buyer_ss:czfss,seller_ys:czfys1,seller_ss:czfss1,type:2,operator:'11'},
			success:save_status
		});
}

function showdiv1(){
	$("#cjzl").css("color","black");
	$("#xgyj").css("color","#3F90E8");
	$("#cjkh").css("color","#3F90E8");
	$("#skmx").css("color","#3F90E8");
	$("#dszy").css("color","#3F90E8");
	$("#other").css("color","#3F90E8");
	$("#selltable1").css("display","block");
	$("#selltable2").css("display","none");
	$("#selltable3").css("display","none");
	$("#selltable4").css("display","none");
	$("#selltable5").css("display","none");
	$("#selltable6").css("display","none");
}

function showdiv2(){
	$("#cjzl").css("color","#3F90E8");
	$("#xgyj").css("color","black");
	$("#cjkh").css("color","#3F90E8");
	$("#skmx").css("color","#3F90E8");
	$("#dszy").css("color","#3F90E8");
	$("#other").css("color","#3F90E8");
	$("#selltable1").css("display","none");
	$("#selltable2").css("display","block");
	$("#selltable3").css("display","none");
	$("#selltable4").css("display","none");
	$("#selltable5").css("display","none");
	$("#selltable6").css("display","none");
}

function showdiv6(){
	$("#cjzl").css("color","#3F90E8");
	$("#xgyj").css("color","#3F90E8");
	$("#cjkh").css("color","#3F90E8");
	$("#skmx").css("color","#3F90E8");
	$("#dszy").css("color","#3F90E8");
	$("#other").css("color","black");
	$("#selltable1").css("display","none");
	$("#selltable2").css("display","none");
	$("#selltable3").css("display","none");
	$("#selltable4").css("display","none");
	$("#selltable5").css("display","none");
	$("#selltable6").css("display","block");
}

function rent_check_value(obj){
	var value=$(obj).val();
	var i=value.length;
	var re=new RegExp("[0-9]{"+i+"}","g");
	if(value!=''){
		if(!re.test(value)){
			alert("這裡只能為數字哦");
			$(obj).val("");
		}
	}
}

function save_status(data){
	mydialog.close();
	if(data.status===0){
		art.dialog({lock:true,title:'提示',content:'没有权限',ok:function(){}});
	}else if(data.status===2){
		art.dialog({lock:true,title:'提示',content:'非法訪問',ok:function(){}});
	}else if(data.status===3){
		art.dialog({lock:true,title:'提示',content:data.info,ok:function(){}});
	}else if(data.status===1){
		art.dialog({lock:true,title:'提示',content:data.info,ok:function(){
			location.reload();
		}});
	}
}